package com.cy.pj.common.controller;

import com.cy.pj.common.pojo.Goods;
import com.cy.pj.common.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @RequestMapping("doGoodsUI")
    public String doGoodsUI(Model model){
        List<Goods> list = goodsService.findGoods();
        model.addAttribute("list",list);
        return "goods";
    }
    @RequestMapping("doDelete/{id}")
    public String doDelete(@PathVariable Integer id){
//        System.out.println("====================="+id);
         goodsService.doDelete(id);
         return "redirect:/doGoodsUI";
    }
    @RequestMapping("doadd")
    public String doadd(){
        return "add";
    }
    @RequestMapping("doInsert")
    public String doInsert(Goods goods){
        goodsService.doInsert(goods);
        return "redirect:/doGoodsUI";
    }

    @RequestMapping("goUpdate/{id}")
    public String goUpdate(@PathVariable Integer id,Model model){
        System.out.println("====================="+id);
        Goods goods = goodsService.findById(id);
        model.addAttribute("goods",goods);
        return "update";
    }
    @RequestMapping("doUpdate")
    public String doUpdate(Goods goods){
        goodsService.doUpdate(goods);
        return "redirect:/doGoodsUI";
    }

}
